<?php
// application/resources/View.php
/**
 * Resource_View
 *
 * demo-zf application
 *
 * @author Adam Pilacki <adam.pilacki@gmail.com>
 */
final class Resource_View
    extends Lib_ResourceAbstract
{

    /**
     * @return Zend_View
     */
    protected final function _getResource()
    {
        $options = $this->getOptions();
        $title   = '';
        if (array_key_exists('title', $options)) {
            $title = $options['title'];
            unset($options['title']);
        }

        /* retrieve existant view instead of create new one */
//        $view = new Zend_View($options);
        /* @var $view Zend_View */
        $view = Zend_Controller_Action_HelperBroker::getStaticHelper('ViewRenderer')->getActionController()->view;
        $view->setScriptPath($options['scriptPath']);

        /* Set headers */
        $view->doctype('XHTML1_STRICT');
        $view->headTitle($title);
        $view->headLink()->appendStylesheet(Zend_Controller_Front::getInstance()->getBaseUrl() . '/css/' . Zend_Registry::get('moduleName') . '.css');
        $view->headLink()->appendStylesheet(Zend_Controller_Front::getInstance()->getBaseUrl() . '/css/common.css');
        $view->headMeta()->appendHttpEquiv('Content-Type', 'text/html; charset=UTF-8')
            ->appendName('keywords', '')
            ->appendName('description', '')
            ->appendName('robots', 'nofollow')
//        $view->headScript()->appendFile('/js/analytics.js')
        ;
        $view->setEncoding('UTF-8');

        /**
         * Set up dojo
         * use default CDN from google
         * CDN version must be >= 1.3.0 because of IE 8.0 compatibility
         */
        $view->addHelperPath('Zend/Dojo/View/Helper/', 'Zend_Dojo_View_Helper');
//        Zend_Dojo::enableView($view);

        Zend_Dojo_View_Helper_Dojo::setUseDeclarative();
        $view->dojo()
            ->setDjConfigOption('parseOnLoad', true)
            ->setDjConfigOption('isDebug', APPLICATION_ENV != 'production')
            ->setDjConfigOption('usePlainJson', true)
            ->setCdnVersion('1.3.1')
            ->addStyleSheetModule('dijit.themes.tundra')
            ->enable()
//            ->requireModule('dojo.parser')
//            ->setLocalPath(Zend_Controller_Front::getInstance()->getBaseUrl() . '/js/dojo-release-1.3.1/dojo/dojo.js')
        ;

        /* Set translator to view */
//        $view->translate()->setTranslator(Zend_Registry::get('translator'));
        $view->translate()->setTranslator($this->getBootstrap()->getResource('Translate'));

        return $view;
    }
}